/**
 * @param {number} n
 * @return {number}
 */
export var arrangeCoins = function (n) {
  let [left, right] = [1, n]
  let ans = left
  while (left <= right) {
    const mid = left + Math.floor((right - left) / 2)
    const sum = (mid * (mid + 1)) / 2
    if (sum === n) return mid
    if (sum < n) {
      ans = mid
      left = mid + 1
    } else right = mid - 1
  }
  return ans
}
